﻿using System;

namespace _50.泛型方法
{
    class Program
    {
        static void Main(string[] args)
        {
            //普通方法的调用
            Ran();
            //泛型方法的调用
            //Ran1<int>(50, 30);
            //Ran2<string, int>("耀", 6);
            //Ran3<string, float>("耀啊",1.98f);
            //Ran4<string, string>("啊", "男");
            //person a = new person();
            //RanPerson<person, string>(a, "真好");
            //ClassA<int> L = new ClassA<int>();
            //ClassB<string, int> P = new ClassB<string, int>();
            //P.b("a", 10);
            //L.Test(30);
            //泛型方法的约束
            //My<int, string>(123,"456");
            //Spera s = new Spera();
            //My1<int, string, Spera>(123, "456", s);
            //Spera1 s1 = new Spera1();
            //My2<int, string, Spera, Spera>(123, "456", s1, s);
            //Spera2 s2 = new Spera2();
            //s2.Run();
            //My3<int, string, Spera,Spera,ISperal>(123, "456", s1 ,s , s2 );
            //int a = 30;
            //int b = 40;
            //My4<int,int> (ref a,ref b);
            //泛型类的约束
            LookA<int> L = new LookA<int>();
            L.Look(10);
            LookB<string,LookC> L1 = new LookB<string,LookC>();
            LookC g = new LookC();
            L1.Look("傻逼",g);
            Console.WriteLine("--------------------");
            LookC c = new LookC();
            LookB<LookC,LookD> L2 = new LookB<LookC,LookD>();
            LookD D = new LookD();
            L2.Look(c,D);
            LookE<IlookAinterface> looke = new LookE<IlookAinterface>();
            looke.MyLook();
            LookF a = new LookF();
            a.MyLook();

            
           
        }
        //普通方法
        public static void Ran()
        {

        }
        //泛型方法 <T>表示某种类型 ，T a 和 T b 表示某种类型的参数
        public static void Ran1<T>(T a ,T b)
        {
            Console.WriteLine(a+b.ToString());
        }
        public static void Ran2<yao, xin>(yao a , xin b)
        {
            Console.WriteLine("我叫{0}，我今年{1}岁了",a,b);
        }
        public static float Ran3<zz,zx>(zz a ,zx b)
        {
            Console.WriteLine("我叫{0}，我身高{1}",a,b);
            object obj = b;
            return (float)obj;
        }
        public static string Ran4<aa,bb>(aa a,bb b)
        {
            Console.WriteLine("我叫{0}，我是{1}生",a,b);
            return b.ToString();
        }
        public static void RanPerson<a1,a2>(a1 a,a2 aa)
        {
            object obj = a;
            person p = (person)obj;
            p.A();
            Console.WriteLine(aa);
        }
        //关键字where用来约束泛型方法
        //struct 表示值类型 
        //class 表示引用类型
         public static void My<T, A>(T a, A b) where T : struct where A : class
        {
            Console.WriteLine("我今年{0}，我是{1}",a,b);
        }
        public static void My1<T, A,B>(T a, A b,B c) where T : struct where A : class where B:new()
        {
            //调用引用类型 ，先把引用类型转为最基础的类，然后在将最基础的类强转成他本身的类
            object obj = c;
            Spera sp = (Spera)obj;
            sp.a();
            
            Console.WriteLine(a+b.ToString());
        }
        public static void My2<T, A, B,C>(T a, A b, B c,C d) where T : struct where A : class where C : Spera where B : new()
        {
            Console.WriteLine("我今年{0}，我是{1}", a, b);
        }
        public static void My3<T, A, B, C,D>(T a, A b, B c, C d,D e) where T : struct where A : class where C : Spera where D:ISperal where B : new()
        {
            Console.WriteLine("我今年{0}，我是{1}", a, b);
        }
        public static void My4<A, B>(ref A number, ref B number1) where A : struct where B : struct
        {
            Console.WriteLine(number.ToString()+number1.ToString());
        }


    }
    class Spera
    {
        public Spera()
        {
            Console.WriteLine("------------");
        }
        public void a()
        {
            Console.WriteLine("跑起来了");
        }
    }
    class Spera1:Spera
    {

    }
    class Spera2 : ISperal
    {
        public void Run()
        {
            Console.WriteLine("跑起来了");
        }
    }
    interface ISperal
    {
         void Run();
    }
}
